package top.dingyingying.springboot3.exam.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import top.dingyingying.springboot3.base.PageBean;
import top.dingyingying.springboot3.base.R;
import top.dingyingying.springboot3.exam.TbExamInfo;
import top.dingyingying.springboot3.exam.TbExamInfoMapper;
import top.dingyingying.springboot3.exam.TbExamInfoService;
import top.dingyingying.springboot3.vo.PageVo;

@Service
@RequiredArgsConstructor
@Slf4j
public class TbExamInfoServiceimpl implements TbExamInfoService {
    private final TbExamInfoMapper tbExamInfoMapper;



    @Override
    public R<String> insert(TbExamInfo tbExamInfo){
       int i = tbExamInfoMapper.insert(tbExamInfo);
       return i == 1 ? R.ok("新增成功", null) : R.fail("添加失败", null);
    }

    @Override
    public R<PageVo<TbExamInfo>> query(TbExamInfo tbExamInfo, PageBean pageBean){
        IPage<TbExamInfo> page = new Page<>(pageBean.getPageNumber(), pageBean.getPageSize());
        QueryWrapper<TbExamInfo> wrapper = new QueryWrapper<>();
        wrapper.like(StringUtils.hasText(tbExamInfo.getExamInfo()),
                "exam_info", tbExamInfo.getExamInfo());
        wrapper.like(StringUtils.hasText(tbExamInfo.getExamSubject()),
                "exam_subject", tbExamInfo.getExamSubject());
        page = tbExamInfoMapper.selectPage(page, wrapper);
        return  R.ok(page);

    }

}
